package HLLib.userControl.HLPanelPickUp;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLGraphics_H;
import HLLib.base.HLImage;
import HLLib.base.HLString;
import HLLib.control.HLPanel;
import HLLib.control.HLPhotoFrame;

public class HLIconNameDesPanel extends HLPanel {
    public static final int PHOTO_X = 3;

    public static final int PHOTO_Y = 5;

    public static final int PHOTO_TO_TEXT = 10;

    public static final int TEXT_Y = 2;

    HLPhotoFrame photoFrame;

    int xText;

    public int selectColor = 0xffff00;

    public int color = 0xffecf3fd;

    Image img[];

    HLString name;

    HLImage icon;

    public int id;

    public HLIconNameDesPanel(HLImage icon, HLString name, int width, Image img[], int id) {
        this.id = id;
        this.icon = icon;
        this.name = name;
        this.width = (short) width;
        this.img = img;
        tabelStop = true;
        photoFrame = new HLPhotoFrame(icon);
        photoFrame.x = PHOTO_X;
        photoFrame.y = PHOTO_Y;

        Add(photoFrame);

        xText = PHOTO_X + photoFrame.width + PHOTO_TO_TEXT;
        this.height = Math.max(TEXT_Y + HLGraphics.StringHeight() + TEXT_Y + HLGraphics.StringHeight() + 2, photoFrame.height + PHOTO_Y * 2);
    }

    public void AdjustSize() {
        if (parent != null) {
            parent.AdjustSize();
        }
    }

    public void Logic() {

        super.Logic();
        if (IsFocus()) {
            RefreshEvent(GetScreenX(), GetScreenY(), GAME_BUTTON_ACTION);
        }
    }

    public void Refresh() {
        super.Refresh();

    }

    public void Render(HLGraphics g) {
        // super.Render(g);
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        g.FillRect(screenX, screenY, width, height, 0xffffff);
        if (IsFocus()) {
            g.FillRect(screenX, screenY, width, height, HLPanelGroup.SELECTED_COLOR);// d0d9f2);//0xd0ebf2);
            g.DrawImage(new HLImage(img[2]), screenX + width - img[2].getWidth() - 5, screenY + (height - img[2].getHeight() >> 1), HLGraphics_H.TRANS_NONE);
        } else {

        }
        xText = PHOTO_X + photoFrame.width + PHOTO_TO_TEXT;
        int offsetX = screenX + xText;
        int offsetY = screenY + TEXT_Y;

        g.DrawStringAdjustable(name, 0, 0, offsetX + photoFrame.width + 10, screenY, width, height, TEXT_STYLE_NORMAL, LEFT_VCENTER);

        photoFrame.Render(g);

    }

}
